package com.tbit.uqbike.service.base.impl;


import com.tbit.uqbike.service.base.QuartzJobService;

public class QuartzJobServiceImpl implements QuartzJobService {
    /*
    @Autowired
    private MachineBorrowService machineBorrowService;
    @Autowired
    private MachineService machineService;
    @Autowired
    private AlarmMsgService alarmMsgService;
    @Autowired
    private TerPositionService terPositionService;

    @Override
    public void notifyBorrowLongTime() {
        List<MachineBorrowNotify> machineBorrowNotifys = machineBorrowService.getBorrowing();
        if (machineBorrowNotifys.size() > 0) {
            LogUtil.info("当前借用车辆[" + machineBorrowNotifys.size() + "]");
            for (MachineBorrowNotify machineBorrowNotify : machineBorrowNotifys) {
                //判断借车时间是否超过3小时
                if (DateTimeUtil.getHour(machineBorrowNotify.getStartTime()) > 3) {
                    LogUtil.info("用户[" + machineBorrowNotify.getPhone() + "]借用车辆超时，订单号[" + machineBorrowNotify.getOrderNO() + "]");
                }
            }
        }

    }

    @Override
    public void synMachineData() {
        //同步时间
        String synTime = DateTimeUtil.getNowTime();

        //同步数据
        List<MachineSimple> machines = machineService.getByJoinTime(SystemData.lastSynTime);

        if (machines.size() > 0) {
            LogUtil.info("同步设备数据[" + machines.size() + "]");

            for (MachineSimple machine : machines) {
                SystemData.machineNOMachineMap.put(machine.getMachineNO(), machine);
            }
        }

        //更新同步时间
        SystemData.lastSynTime = synTime;
    }

    @Override
    public void addAlarmBatch() {

        //数据批量入库
        if (SystemData.alarmMsgs.size() > 0) {
            LogUtil.info("实时告警入库[" + SystemData.alarmMsgs.size() + "]");

            //复制数据
            List<AlarmMsg> alarmMsgs = new ArrayList<AlarmMsg>(SystemData.alarmMsgs);

            //清空数据
            SystemData.alarmMsgs.clear();

            alarmMsgService.addBatch(alarmMsgs);
        }
    }

    @Override
    public void clearInvalidAlarm() {
        LogUtil.info("清除无效消息");

        //清除3天以前的告警数据
        alarmMsgService.clearInvalid(3);
    }

    @Override
    public void synChinaRLData() {
        List<TerPosition> terPositions = terPositionService.getAll();

        if (terPositions.size() > 0) {
            LogUtil.info("同步热力图数据[" + terPositions.size() + "]");

            JSONArray array1 = new JSONArray();
            JSONArray array2 = new JSONArray();
            array1.add(array2);

            for (TerPosition p : terPositions) {
                JSONObject point = new JSONObject();
                Double[] pointArray = {p.getLon(), p.getLat()};
                point.put("geoCoord", pointArray);

                array2.add(point);
            }

            //生成路径
            String path = this.getClass().getClassLoader().getResource("").getPath().replace("WEB-INF/classes/", "bigData");

            //删除文件
            FileUtils.deleteFile(path + "\\china-point.json");
            //生成txt文件
            FileUtils.writeToTxt(path + "\\china-point.json", array1.toJSONString());
        }
    }
    */

}  